package com.ruoyi.qyj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qyj.domain.TbRecordPatrol;
import com.ruoyi.qyj.service.ITbRecordPatrolService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查记录信息Controller
 * 
 * @author yellow
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/qyj/record")
public class TbRecordPatrolController extends BaseController
{
    @Autowired
    private ITbRecordPatrolService tbRecordPatrolService;

    /**
     * 查询巡查记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRecordPatrol tbRecordPatrol)
    {
        startPage();
        List<TbRecordPatrol> list = tbRecordPatrolService.selectTbRecordPatrolList(tbRecordPatrol);
        return getDataTable(list);
    }

    /**
     * 导出巡查记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:export')")
    @Log(title = "巡查记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRecordPatrol tbRecordPatrol)
    {
        List<TbRecordPatrol> list = tbRecordPatrolService.selectTbRecordPatrolList(tbRecordPatrol);
        ExcelUtil<TbRecordPatrol> util = new ExcelUtil<TbRecordPatrol>(TbRecordPatrol.class);
        util.exportExcel(response, list, "巡查记录信息数据");
    }

    /**
     * 获取巡查记录信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(tbRecordPatrolService.selectTbRecordPatrolByRecordId(recordId));
    }

    /**
     * 新增巡查记录信息
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:add')")
    @Log(title = "巡查记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRecordPatrol tbRecordPatrol)
    {
        tbRecordPatrol.setCreateBy(getUsername());
        return toAjax(tbRecordPatrolService.insertTbRecordPatrol(tbRecordPatrol));
    }

    /**
     * 修改巡查记录信息
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:edit')")
    @Log(title = "巡查记录信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRecordPatrol tbRecordPatrol)
    {
        tbRecordPatrol.setUpdateBy(getUsername());
        return toAjax(tbRecordPatrolService.updateTbRecordPatrol(tbRecordPatrol));
    }

    /**
     * 删除巡查记录信息
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:remove')")
    @Log(title = "巡查记录信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(tbRecordPatrolService.deleteTbRecordPatrolByRecordIds(recordIds));
    }

    @RequestMapping("/upload")
    @ResponseBody
    public AjaxResult uploadFile(MultipartFile file, HttpServletResponse response) {
        return toAjax(tbRecordPatrolService.importExcel(file));
    }


    /**
     * 获取total统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('qyj:record:query')")
    @RequestMapping("/total")
    public AjaxResult getTotalInfo()
    {
        return AjaxResult.success(tbRecordPatrolService.selectTbRecordPatrolTotal());
    }

}
